package net.hn.hnms.biz.safety.location.repository;

import net.hn.hnms.biz.safety.location.domain.JxryHisPersonnelinfoEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;

/**
 * 智呈物联 pan'sx
 * 2022/9/2 9:46
 * 1.0 version
 */
@Repository
public interface JxryHisPersonnelinfoRepository extends JpaRepository<JxryHisPersonnelinfoEntity, BigInteger> {
    @Query(value = "SELECT t.*,tt.dept_name as dept,tt.duty FROM dwd_jxry_his_personnelinfo t " +
            "JOIN dwd_jxry_base_personnelinfo tt on (t.staff_code=tt.staff_code) " +
            " where CASE when  :duty != '' then   tt.duty = :duty else  1=1  end " +
            " and CASE when  :dept != '' then tt.dept_name = :dept else 1=1 end  " +
            " and CASE when  :staffName != '' then t.staff_name like CONCAT(:staffName, '%') else 1=1 end " +
            " and CASE when  :leader != '' then t.mine_leader = :leader else 1=1 end " +
            " and CASE when  :mineCode != '' then t.mine_code = :mineCode else 1=1 end " +
            " and CASE when  :mineCode != '' then tt.mine_code = :mineCode else 1=1 end " +
            " and CASE when  :beginTime != '' then t.data_time >= to_timestamp(:beginTime,'yyyy-MM-dd hh24:mi:ss') else 1=1 end " +
            " and CASE when  :endTime != '' then t.data_time <= to_timestamp(:endTime,'yyyy-MM-dd hh24:mi:ss') else 1=1 end ", nativeQuery = true)
    Page<JxryHisPersonnelinfoEntity> getPageDate(@Param("duty") String duty, @Param("dept") String dept,
                                                 @Param("staffName")String staffName, @Param("leader") String leader,
                                                 @Param("beginTime") String beginTime,
                                                 @Param("endTime") String endTime,
                                                 Pageable pageable,
                                                 @Param("mineCode") String mineCode);
}
